package com.cy.bus.ui;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.cy.utils.SysParam;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

/**
 * 我Fragment
 * @author CY
 *
 */
public class MeFragment extends Fragment {

	private View view;
	private String[] names1 = new String[]{"重大城科", "功能介绍" , "帮助反馈" , "检查更新"};
	private int[] name_img_1 = new int[]{
			R.drawable.ic_menu_star,
			R.drawable.ic_menu_find,
			R.drawable.ic_menu_help,
			R.drawable.ic_menu_refresh};
	private String[] names2 = new String[]{"关于我们" , "设置", "退出"};
	private int[] name_img_2 = new int[]{R.drawable.ic_menu_allfriends,R.drawable.ic_menu_preferences,R.drawable.ic_menu_home};
	private ListView listView1;
	private ListView listView2;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		view = inflater.inflate(R.layout.fragment_me, container, false);
		listView1 = (ListView) view.findViewById(R.id.me_listView1);
		listView2 = (ListView) view.findViewById(R.id.me_listView2);
		
		final List<Map<String, Object>> data1 = new ArrayList<Map<String, Object>>();
		for(int i = 0; i < names1.length; i ++) {
			Map<String, Object> listItem = new HashMap<String, Object>();
			listItem.put("img", name_img_1[i]);
			listItem.put("name", names1[i]);
			data1.add(listItem);
		}
		SimpleAdapter adapter1 = new SimpleAdapter(this.getActivity(),data1,R.layout.item_me,
				new String[]{"img","name"}, 
				new int[]{R.id.me_item_img,R.id.me_item_tv});
		listView1.setAdapter(adapter1);
		listView1.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				if(data1.get(position).get("name").equals("重大城科")) {
					Toast.makeText(MeFragment.this.getActivity(), "厚德、博学、求实、创新", Toast.LENGTH_SHORT).show();
                } else if (data1.get(position).get("name").equals("功能介绍")) {
                	Toast.makeText(MeFragment.this.getActivity(), "输入公交路线或公交车站即可查询，如需换乘查询在公交车站中加空格即可", Toast.LENGTH_LONG).show();
                } else if (data1.get(position).get("name").equals("帮助反馈")) {
                	Toast.makeText(MeFragment.this.getActivity(), "Tel:17608009351", Toast.LENGTH_SHORT).show();
                } else if (data1.get(position).get("name").equals("检查更新")) {
                	Toast.makeText(MeFragment.this.getActivity(), "已经是最新版", Toast.LENGTH_SHORT).show();
                }
			}
		});
		
		
		final List<Map<String, Object>> data2 = new ArrayList<Map<String, Object>>();
		for(int i = 0; i < names2.length; i ++) {
			Map<String, Object> listItem = new HashMap<String, Object>();
			listItem.put("img", name_img_2[i]);
			listItem.put("name", names2[i]);
			data2.add(listItem);
		}
		SimpleAdapter adapter2 = new SimpleAdapter(this.getActivity(),data2,R.layout.item_me,
				new String[]{"img","name"}, 
				new int[]{R.id.me_item_img,R.id.me_item_tv});
		listView2.setAdapter(adapter2);
		listView2.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				if(data2.get(position).get("name").equals("退出")) {
					MeFragment.this.getActivity().finish();
                } else if (data2.get(position).get("name").equals("关于我们")) {
                	Toast.makeText(MeFragment.this.getActivity(), "出品人：崔阳", Toast.LENGTH_SHORT).show();
                } else if (data2.get(position).get("name").equals("设置")) {
                	if(SysParam.read("full").equals("false")) {
                		MeFragment.this.getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
                		Toast.makeText(MeFragment.this.getActivity(), "已设置为全屏", Toast.LENGTH_SHORT).show();
                		SysParam.write("full", "true");
                	} else {
                		MeFragment.this.getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
                		Toast.makeText(MeFragment.this.getActivity(), "已退出全屏", Toast.LENGTH_SHORT).show();
                		SysParam.write("full", "false");
                	}
                }
			}
		});
		
		return view;
	}
	
}
